package kr.hkit.powerjava.chapter11;
//다형성..
class Fly {
	String name;

	@Override
	public String toString() {
		return name;
	}
	
}

public class Car {
	int speed;
	int gear;
	public String color;
	
	public void speedUp(int increment) {
		speed = speed + increment;
	}
	
	public void speedDown(int decrement) {
		speed = speed - decrement;
	}

	@Override
	public String toString() {
		return String.format("Object[%s] -> [%s, %s, %s]",
				super.toString(), speed, gear, color);
	}
	
	public  static void main(String[] args) {
		Car car = new Car();
		car.gear = 1;
		car.color = "red";
		car.speedUp(60);
/*		System.out.println(car);
		
		
		Object obj = car;
		System.out.println(obj.toString());*/
		
		Car car2 = new Car();
		car2.gear = 2;
		car2.color = "blue";
		car2.speedUp(80);
		
		Fly fly = new Fly();
		fly.name = "fly01";
		
		Fly fly2 = new Fly();
		fly2.name = "fly02";
		
		Car[] arrCar = new Car[2];
		Fly[] arrFly = new Fly[2];
		
		arrCar[0] = car;
		arrCar[1] = car2;
		
		arrFly[0] = fly;
		arrFly[1] = fly2;
		
		prnArr(arrCar);
		prnArr(arrFly);
		
		Object[] arrObj = new Object[4];
		arrObj[0] = car;
		arrObj[1] = car2;
		arrObj[2] = fly;
		arrObj[3] = fly2;
		
		prnArr(arrObj);
	}

	private static void prnArr(Object[] arrObj) {
		for (int i = 0; i < arrObj.length; i++) {
			System.out.println(arrObj[i]);
		}
		System.out.println();
	}

	private static void prnArr(Fly[] arrFly) {
		for (int i = 0; i < arrFly.length; i++) {
			System.out.println(arrFly[i]);			
		}
		System.out.println();		
	}

	private static void prnArr(Car[] arrCar) {
		for (int i = 0; i < arrCar.length; i++) {
			System.out.println(arrCar[i]);
		}
		System.out.println();
	}
	
}